﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DBUtility;

public partial class Manageweb_Control_LeftNewsForLock : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ControlDataInit();
    }


    #region ControlDataInit
    protected void ControlDataInit()
    {
        string SQLstr = "SELECT * FROM [NewsClass] WHERE [NC_IsLock]=true ORDER BY [NC_ClassCode]";

        DataSet DS_NewsClass = AccHelper.GetDataSet(SQLstr, "NewsClassForLock");

        DataTable DT_NewsClass = DS_NewsClass.Tables["NewsClassForLock"];

        InitTree(TV_NewsForLock.Nodes, "0", DT_NewsClass);

        DS_NewsClass.Clear();

        DS_NewsClass.Dispose();
    }
    #endregion


    #region InitTree
    private void InitTree(TreeNodeCollection tnParent, string parentId, DataTable dt)
    {
        foreach (DataRow dr in dt.Select("[NC_ParentID]='" + parentId + "'"))
        {
            TreeNode tn = new TreeNode();
            
            tn.Value = dr["NC_ID"].ToString();
            tn.Text = dr["NC_Title"].ToString();
            tn.Target = "mainFrame";
            tn.NavigateUrl = "~/Manageweb/ManageNews/ManageNews.aspx?ClassID=" + dr["NC_ID"].ToString();

            tnParent.Add(tn);


            TreeNode tn2 = new TreeNode();

            tn2.Value = dr["NC_ID"].ToString();
            tn2.Text = "添加" + dr["NC_Title"].ToString();
            tn2.Target = "mainFrame";
            tn2.NavigateUrl = "~/Manageweb/ManageNews/AddNews.aspx?ClassID=" + dr["NC_ID"].ToString();

            tn.ChildNodes.Add(tn2);


            TreeNode tn3 = new TreeNode();

            tn3.Value = dr["NC_ID"].ToString();
            tn3.Text = "管理" + dr["NC_Title"].ToString();
            tn3.Target = "mainFrame";
            tn3.NavigateUrl = "~/Manageweb/ManageNews/ManageNews.aspx?ClassID=" + dr["NC_ID"].ToString();

            tn.ChildNodes.Add(tn3);

            InitTree(tnParent[tnParent.Count - 1].ChildNodes, tn.Value, dt);
        }
    }
    #endregion
}
